Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
selenium-webdriver
Advanced tools
The official WebDriver JavaScript bindings from the Selenium project
The selenium-webdriver npm package is a browser automation library that provides an API for interacting with web browsers. It allows for the automation of web applications for testing purposes, but it's also used for automating web-based administration tasks. It supports multiple browsers including Chrome, Firefox, Internet Explorer, and Safari.
Browser Navigation
This feature allows for navigating to a web page. The code sample demonstrates how to open Firefox and navigate to Google's homepage.
const {Builder} = require('selenium-webdriver');
let driver = new Builder().forBrowser('firefox').build();
driver.get('http://www.google.com');
Element Interaction
This feature enables interaction with elements on a web page, such as input fields and buttons. The code sample shows how to find a search input by its name attribute and type 'selenium' into it.
const {Builder, By} = require('selenium-webdriver');
let driver = new Builder().forBrowser('firefox').build();
driver.findElement(By.name('q')).sendKeys('selenium');
Wait for Elements
This feature allows scripts to wait for elements to become available or visible on the page before interacting with them. The code sample demonstrates waiting up to 10 seconds for a search input to be located.
const {Builder, By, until} = require('selenium-webdriver');
let driver = new Builder().forBrowser('firefox').build();
driver.wait(until.elementLocated(By.name('q')), 10000);
Puppeteer is a Node library which provides a high-level API to control Chrome or Chromium over the DevTools Protocol. It is similar to selenium-webdriver but is specifically designed for Chrome and Chromium browsers. Puppeteer is often considered faster for browser automation tasks, especially with headless Chrome.
WebdriverIO is an automation library that wraps around the W3C WebDriver API. It provides a simpler API compared to selenium-webdriver and integrates well with modern testing frameworks. WebdriverIO supports both web and mobile browsers, making it a versatile choice for cross-platform testing.
Nightwatch.js is an automated testing framework for web applications and websites, written in Node.js. It uses the W3C WebDriver API for browser automation. It is designed to simplify the process of setting up continuous integration and writing automated tests. Nightwatch has a cleaner syntax compared to selenium-webdriver, which might be easier for beginners.
Selenium is a browser automation library. Most often used for testing web-applications, Selenium may be used for any task that requires automating interaction with the browser.
Selenium may be installed via npm with
npm install selenium-webdriver
Out of the box, Selenium includes everything you need to work with Firefox. You will need to download additional components to work with the other major browsers. The drivers for Chrome, PhantomJS, Opera, and Microsoft's IE and Edge web browsers are all standalone executables that should be available on your PATH. The SafariDriver browser extension should be installed in your browser before using Selenium; we recommend disabling the extension when using the browser without Selenium or installing the extension in a profile only used for testing.
Browser | Component |
---|---|
Chrome | chromedriver(.exe) |
Internet Explorer | IEDriverServer.exe |
Edge | MicrosoftWebDriver.msi |
PhantomJS | phantomjs(.exe) |
Opera | operadriver(.exe) |
Safari | SafariDriver.safariextz |
The sample below and others are included in the example
directory. You may
also find the tests for selenium-webdriver informative.
var webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
var driver = new webdriver.Builder()
.forBrowser('firefox')
.build();
driver.get('http://www.google.com/ncr');
driver.findElement(By.name('q')).sendKeys('webdriver');
driver.findElement(By.name('btnG')).click();
driver.wait(until.titleIs('webdriver - Google Search'), 1000);
driver.quit();
The Builder
class is your one-stop shop for configuring new WebDriver
instances. Rather than clutter your code with branches for the various browsers,
the builder lets you set all options in one flow. When you call
Builder#build()
, all options irrelevant to the selected browser are dropped:
var webdriver = require('selenium-webdriver'),
chrome = require('selenium-webdriver/chrome'),
firefox = require('selenium-webdriver/firefox');
var driver = new webdriver.Builder()
.forBrowser('firefox')
.setChromeOptions(/* ... */)
.setFirefoxOptions(/* ... */)
.build();
Why would you want to configure options irrelevant to the target browser? The
Builder
's API defines your default configuration. You can change the target
browser at runtime through the SELENIUM_BROWSER
environment variable. For
example, the example/google_search.js
script is configured to run against
Firefox. You can run the example against other browsers just by changing the
runtime environment
# cd node_modules/selenium-webdriver
node example/google_search
SELENIUM_BROWSER=chrome node example/google_search
SELENIUM_BROWSER=safari node example/google_search
The standalone Selenium Server acts as a proxy between your script and the browser-specific drivers. The server may be used when running locally, but it's not recommend as it introduces an extra hop for each request and will slow things down. The server is required, however, to use a browser on a remote host (most browser drivers, like the IEDriverServer, do not accept remote connections).
To use the Selenium Server, you will need to install the JDK and download the latest server from Selenium. Once downloaded, run the server with
java -jar selenium-server-standalone-2.45.0.jar
You may configure your tests to run against a remote server through the Builder API:
var driver = new webdriver.Builder()
.forBrowser('firefox')
.usingServer('http://localhost:4444/wd/hub')
.build();
Or change the Builder's configuration at runtime with the SELENIUM_REMOTE_URL
environment variable:
SELENIUM_REMOTE_URL="http://localhost:4444/wd/hub" node script.js
You can experiment with these options using the example/google_search.js
script provided with selenium-webdriver
.
API documentation is available online from the Selenium project. Additional resources include
Contributions are accepted either through GitHub pull requests or patches via the Selenium issue tracker. You must sign our Contributor License Agreement before your changes will be accepted.
Each version of selenium-webdriver will support the latest semver-minor version of the LTS and stable Node releases. All semver-major & semver-minor versions between the LTS and stable release will have "best effort" support. Following a Selenium release, any semver-minor Node releases will also have "best effort" support. Releases older than the latest LTS, semver-major releases, and all unstable release branches (e.g. "v.Next") are considered strictly unsupported.
For example, suppose the current LTS and stable releases are v4.2.4 and v5.4.1, respectively. Then a Selenium release would have the following support levels:
Version | Support |
---|---|
<= 4.1 | unsupported |
4.2 | supported |
5.0-3 | best effort |
5.4 | supported |
>= 5.5 | best effort |
v.Next | unsupported |
supported: A selenium-webdriver release will be API compatible with the platform API, without the use of runtime flags.
best effort: Bugs will be investigated as time permits. API compatibility is only guaranteed where required by a supported release. This effectively means the adoption of new JS features, such as ES2015 modules, will depend on what is supported in Node's LTS.
unsupported: Bug submissions will be closed as will-not-fix and API compatibility is not guaranteed.
If Node releases a new LTS each October and a new major version every 6 months, the support window for selenium-webdriver will be roughly:
Date | LTS | Stable |
---|---|---|
(current) | 4.2 | 5.0 |
2016-04 | 4.2 | 6.0 |
2016-10 | 6.0 | 7.0 |
2017-04 | 6.0 | 8.0 |
2017-10 | 8.0 | 9.0 |
Please report any issues using the Selenium issue tracker. When using the issue tracker
Licensed to the Software Freedom Conservancy (SFC) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The SFC licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
FAQs
The official WebDriver JavaScript bindings from the Selenium project
We found that selenium-webdriver demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.